#ifndef CHESSBOARD_H_
#define CHESSBOARD_H_

#include "Square.h"
#include "../Pieces/Piece.h"

#include <string>
using namespace std;

namespace Core
{
	class Engine;

	class Chessboard
	{
	public:
		static const int RANKS = 8;
		static const int COLUMNS = 8;
		static bool checkBounds(int r1, int r2, int r3, int r4, bool throwEx);
		static int sign(int val);

		Chessboard();
		~Chessboard(void);

		Square * at(int r, int c) const;

		/*
		* this method finds first piece in a given direct path.
		* throws exception if path is invalid.
		*/
		Piece * findPieceDirect(int r1, int c1, int r2, int c2, bool contnu = true, map<int, Move*>* validMoves = NULL) const;
		/*
		* this method finds first piece in a given diagonal path.
		* throws exception if path is invalid.
		*/
		Piece * findPieceDiagonal(int r1, int c1, int r2, int c2, bool contnu = true, map<int, Move*>* validMoves = NULL) const;
		/*
		* this method finds first piece in a direction (r1, c1) -> (r2, c2) diagonal or direct to the board bounds.
		* NULL means either not found or path was incorrect.
		*/
		Piece * findPieceIfExist(int r1, int c1, int r2, int c2) const;
		/*
		* considers a square if it's under attack by opponent's piece(s).
		*/
		Piece * underAttackBy(int r, int c, ChColor own) const;
		bool underAttackBy(int r, int c, ChColor own, vector<Piece*> * attackers, bool firstPiece = false) const;
		bool isAttackingDiagonal(Piece * p, int r, int c, ChColor own) const;
		bool isAttackingDirect(Piece * p, int r, int c, ChColor own) const;

	private:
		Square * _squares[RANKS][COLUMNS];
	};
}

#endif
